<?php
include ('../__global.php');

class self_index extends ml_controller
{
    var $page;
    var $total;
    public  function init()
    {
        $this->set_access(self::ACCESS_SELF , self::NOACCESS_REDIRECT );
        
//        if ($this->check_permission(ML_PERMISSION_UNVERIFY_CANREAD)) {//激活页面可以返回到登录页面
//            $this->loginProxy(ml_logout);
//        }
    }
    public function initParam()
    {
        $this->page = $this->input('page','G',1);    //页数
    }
    public function checkParam()
    {

    }
    public function main()
    {

        $uid = $this->__visitor['uid'];
        
        $data = array();
        $data['uid'] = $uid;
        //获取用户名片信息    


        $obizUser = ml_biz_user_getinfo::get_instance();
        $obizUser->initUser($uid,$uid);
        $arr = $obizUser->getUserArea();
        $data = array_merge($data,$arr);

        //获得我关注的人的uid
        $oFollow = new ml_model_dbFollow();


        $oFollow->getList($uid,0,200);
        $rs = $oFollow->get_data();
        
        if(is_array($rs) && count($rs) > 0){
            foreach($rs as $k => $v) {
                $uids[] = $v['follow_uid'];
            }
        }else{
            global $defaultUids;
            $uids = $defaultUids;
        }
        
        $begin = ($this->page - 1) * ML_FEED_PAGESIZE * 3;

        $oPic = new ml_model_dbPicFeed();
        $oPic->getListByUids($uid,$begin,ML_FEED_PAGESIZE,$uids);
        $feed = $oPic->get_data();

        //    数据结构不统一
        if(is_array($feed))
        foreach ($feed as $k => $v) {
                
            if(!empty($v['content_rid'])) {
                $feed[$k]['rid'] = $v['content_rid'];
                $rids[] = $v['content_rid'];
            }else{
                $feed[$k]['rid'] = $v['feed_info']['rid'];
                $rids[] = $v['feed_info']['rid'];
            }
            $feed[$k]["pin_type"] = 'verify_other';
        }
        $oContent = new ml_model_dbContent();
        $contents = $oContent->get_content_by_rids($rids);

            
        $pin=new ml_biz_pin_indexData();            

            
        $feed = $pin->output($uid,$feed,$contents);


        if(is_array($feed))
        foreach ($feed as $k => $v) {
                
            switch ($k % 3) {
                case 0: $data['col1'][] = $v;    break;
                case 1: $data['col2'][] = $v;    break;
                case 2: $data['col3'][] = $v;    break;
            }
        }

        //    获得总数

        $rs = $oPic->getCntByUids($uid,$uids);
        $cnt = $oPic->get_data();
        $this->total = isset($cnt[0]) ? $cnt[0] : 0;

        $data['albums'] = ml_tool_getdata::mlJsonData('homehotalum','operate');
        
        $last=$this->total['num']-($this->page-1)* ML_FEED_PAGESIZE * 3 <ML_FEED_PAGESIZE?true:false;
        $this->set_scope_var('$totalPage', floor($this->total['num']/(ML_FEED_PAGESIZE * 3)+1));//总页数
        $this->set_scope_var('$currentPage', intval($this->page));//当前页
        $this->set_scope_var('$segment', 1);
        $this->set_scope_var('$lastSegment', $last);
        
        $o3rdSer=new ml_model_db3rdService();
        //sina
        $rs=$o3rdSer->get3rdServiceUser($uid,1,$wbInfo);
        $this->set_scope_var('$third_id',$wbInfo['3rd_id']);
        
        //已关闭微博关系，跳过步骤
        if ($_COOKIE['closeRelation'] !== 'true') {
        
        
        //微博关系引入
        if (empty($wbInfo['3rd_id'])) {
            $data['3rdfollow']['type'] = 3;
        } else {
            $trd_follows = new ml_biz_extRelation_extFollow();
            $re = $trd_follows->get_meilauser_3rdfollow($uid);
            $data['3rdfollow']['type'] = 1;
            $data['3rdfollow']['data'] = $re;
            if (empty($re)) {
                $re = $trd_follows->get_wb3rdfollow($wbInfo['3rd_id']);
                 ml_tool_sendMq::add_new3rd_extfollow($uid, $wbInfo['3rd_id'], 1, $wbInfo['access_token']);
                $data['3rdfollow']['type'] = 2;
                $data['3rdfollow']['data'] = $re;
                if (empty($re)) {
                    $data['3rdfollow'] = false;
                }
                
            }
            
        }
        }
        
        $this->set_scope_var('$relationType', $data['3rdfollow']['type']);
        
        $this->set_scope_var('$skilltags',$data['skill_tags']);
        $this->set_page_title2('我的首页');
        $this->page_output('self_index' , $data);
    }




}
new self_index();
?>